package com.bins.cloud.stream.mq;

import com.bins.cloud.stream.eo.mq.MqMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
public class RocketLister {

    @Bean
    public Consumer<Message<MqMsg>> topicBConsumer() {
        return msg -> {
            log.info(Thread.currentThread().getName() + " topicBConsumer Receive Messages: " + msg.getPayload().getId());
        };
    }

    @Bean
    public Consumer<Message<MqMsg>> retryConsumer() {
        return msg -> {
            log.info("Receive retry messages:{}-{}", msg.getPayload().getId(), msg.getPayload().getName());
            throw new RuntimeException("mock exception.");
        };
    }

    @Bean
    public Consumer<Message<MqMsg>> broadcastConsumer() {
        return msg -> {
            log.info("Receive broadcast messages:{}-{}", msg.getPayload().getId(), msg.getPayload().getName());
            throw new RuntimeException("mock exception.");
        };
    }
}